package com.hdl.servlet.cart;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hdl.entity.MallCart;

/**
 * 删除多个选中的商品项
 * @author Administrator
 *
 */
@WebServlet("/deleteItems.let")
public class DelItemsServlet extends HttpServlet{
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//获取参数
		String[] ids = req.getParameterValues("uid");
		
		//从session中取出购物车对象 	 调用购物车的删除方法
		MallCart cart = (MallCart) req.getSession().getAttribute("cart");
		cart.removeSelect(ids);
		
		//将购物车存入session
		req.getSession().setAttribute("cart", cart);
		
		//转发
		req.getRequestDispatcher("/myCart.jsp").forward(req, resp);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

}
